<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>蜗牛车辆预约</title>
        <meta name="description" content="蜗牛车辆预约">
        <meta name="keywords" content="蜗牛车辆预约">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <style>
            .avatar-uploader .el-upload {
                border: 1px dashed #d9d9d9;
                border-radius: 6px;
                cursor: pointer;
                position: relative;
                overflow: hidden;
            }
            .avatar-uploader .el-upload:hover {
                border-color: #409EFF;
            }
            .avatar-uploader-icon {
                font-size: 28px;
                color: #8c939d;
                width: 178px;
                height: 178px;
                line-height: 178px;
                text-align: center;
            }
            .avatar {
                width: 178px;
                height: 178px;
                display: block;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>日志管理<small>日志列表</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>日志管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                     <div class="filter-container">
                        <el-input v-model="logSearchDTO.title" placeholder="日志模块" style="width: 200px;" class="filter-item"></el-input>
                         <el-select v-model="logSearchDTO.status" placeholder="请选择状态">
                             <el-option label="成功" value="0"></el-option>
                             <el-option label="失败" value="1"></el-option>
                         </el-select>
                        <el-button class="dalfBut" @click="handleSearch">查询</el-button>
                        <el-button class="dalfBut" @click="handleSearchClear">清空</el-button>
                        <el-button type="primary" class="butT" @click="handleDeleteBatch(undefined)">批量删除</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" @selection-change="handleSelectionChange" stripe highlight-current-row>
                        <el-table-column type="selection" width="55"></el-table-column>
                        <el-table-column prop="id" align="center" label="编号"></el-table-column>
                        <el-table-column prop="title" label="模块" align="center"></el-table-column>
                        <el-table-column prop="businessType" label="操作类型" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" disabled size="mini" v-if="scope.row.businessType == 0">其它</el-button>
                                <el-button type="primary" disabled size="mini" v-if="scope.row.businessType == 1">新增</el-button>
                                <el-button type="primary" disabled size="mini" v-if="scope.row.businessType == 2">修改</el-button>
                                <el-button type="primary" disabled size="mini" v-if="scope.row.businessType == 3">删除</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column prop="operName" label="操作人员" align="center"></el-table-column>
                        <el-table-column prop="status" label="操作状态" align="center">
                            <template slot-scope="scope">
                                <el-button type="success" disabled size="mini" v-if="scope.row.status == 0">成功</el-button>
                                <el-button type="danger" disabled size="mini" v-if="scope.row.status == 1">失败</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column prop="operTime" label="操作时间" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleToEdit(scope.row.id)">详情</el-button>
                            </template>
                        </el-table-column>
                    </el-table>

                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="logSearchDTO.currentPage"
                            :page-sizes="[1, 2, 3, 4]"
                            :page-size="logSearchDTO.pageSize"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="total">
                    </el-pagination>

                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="详情" :visible.sync="addDialogFormVisible" :close-on-click-modal="false">
                            <el-form label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="操作模块">
                                            <sapn>{{logOpre.title + '/' + logOpre.businessType}}</sapn>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="请求地址">
                                            <sapn>{{logOpre.operUrl}}</sapn>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="操作方法">
                                            <sapn>{{logOpre.method}}</sapn>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="请求参数">
                                            <sapn>{{logOpre.operParam}}</sapn>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="响应数据">
                                            <sapn>{{logOpre.jsonResult}}</sapn>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="消耗时间">
                                            <sapn>{{logOpre.costTime + ' 毫秒'}}</sapn>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="addDialogFormVisible = false">返回</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script>
        let vue = new Vue({
            el: '#app',
            data:{
				dataList: [],                       // 分页数据
                logOpre: {},                        // 表单数据
                addDialogFormVisible: false,        // 新增表单是否可见
                logSearchDTO:{                      // 表示搜索的内容
				    title: '',
                    status: '',
                    currentPage: 1,
                    pageSize: 3
                },
                total: 10,                          // 总记录数
                ids: [],                            // 多选列表
            },
            methods: {
                // 初始化查询数据，查询按钮
                handleSearch(){
                    // 发送请求查询数据
                    axios.post("/log/search", this.logSearchDTO).then(res => {
                        this.dataList = res.data.data.data;
                        this.total = res.data.data.total;
                    });
                },
                // 清空搜索内容
                handleSearchClear(){
                    this.logSearchDTO.title = '';
                    this.logSearchDTO.status = '';
                },
                // 每页记录数发生变化触发
                handleSizeChange(pageSize){
                    // 更改数据模型中的每页记录数
                    this.logSearchDTO.pageSize = pageSize;
                    // 重新查询数据
                    this.handleSearch();
                },
                // 页码发生变化触发
                handleCurrentChange(currentPage){
                    // 更改数据模型中的当前页
                    this.logSearchDTO.currentPage = currentPage;
                    // 重新查询数据
                    this.handleSearch();
                },
                // 打开编辑窗口
                handleToEdit(id){
                    axios.get("/log/" + id).then(res => {
                        this.logOpre = res.data.data;
                        this.addDialogFormVisible = true;
                    });
                },
                // 多选事件
                handleSelectionChange(selection){
                    this.ids = selection.map(item => item.id)
                },
                // 批量删除
                handleDeleteBatch(id){
                    if(id){
                        this.ids = id;
                    }
                    if(this.ids == undefined || this.ids.length == 0){
                        this.$message.info("请选择需要删除的数据");
                        return;
                    }
                    this.$confirm('是否确认删除编号为"' + this.ids + '"的数据项？').then(() => {
                        axios.delete("/log/" + this.ids).then(res => {
                            if(res.data.code == 20000){
                                this.$message.success("删除成功");
                                this.handleSearch();
                            }else{
                                this.$message.error("删除失败，请稍后再试");
                            }
                        });
                    }).catch(() => {
                        this.$message.info("取消删除操作");
                    });
                }
            },
            created(){
                this.handleSearch();
            }
        })
    </script>
</html>
